home *** CD-ROM | disk | FTP | other *** search
/ Windows 6-Pak - Disc 5 / Windows 6-Pak (InfoMagic) (Disc 5) (1999).ISO / C&C++Tools / sbparser.exe / anyc / parsanyc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-26  |  2.2 KB  |  98 lines

  1. #include <astsbpar.h> //Link necessary header
  2. #include <stdio.h>
  3.  
  4. int main ()
  5. {
  6.     char  functionStr[255];
  7.     char  xvalStr[255];
  8.     char  yvalStr[255];
  9.     double xyval[2];
  10.  
  11.     //Loading of the csbparse.DLL
  12.     if (InitSTDsbParserDLL() == true) {
  13.         printf("\n\nEnter a function to solve: f(x,y)=");
  14.         scanf("%255s", functionStr);
  15.  
  16.         //Create an sbParser object and receive its HANDLE
  17.         HANDLE hParser;
  18.         hParser = CreateNewParser(functionStr, 2, "xy");
  19.  
  20.         double Result;
  21.         char strResult[30];
  22.         if (GetIsError(hParser))
  23.         {
  24.             //An error has occurred
  25.             printf("\n\nAn error has occured... GlobalError==");
  26.             dtochar(strResult, GetGlobalError(hParser));
  27.             printf(strResult);
  28.  
  29.                Result = 0;
  30.         }
  31.         else
  32.         {
  33.               bool err = false;
  34.             int pos;
  35.  
  36.             printf("\n\nEnter the x value: x=");
  37.             scanf("%255s", xvalStr);
  38.             printf("\nEnter the y value: y=");
  39.                scanf("%255s", yvalStr);
  40.  
  41.             //Convert the strings of the variables to long double
  42.             xyval[0]=chartod(xvalStr,&pos);
  43.             if (pos >= 0)
  44.             {
  45.                 printf("\nThe string of the variable x cannot be converted to long double.");
  46.  
  47.                 err=true;
  48.             }
  49.             xyval[1]=chartod(yvalStr,&pos);
  50.             if (pos >= 0)
  51.             {
  52.                 printf("\nThe string of the variable y cannot be converted to long double.");
  53.  
  54.                 err=true;
  55.             }
  56.  
  57.             if (err == false) {
  58.                 Result = dGetResultExt(hParser, xyval);
  59.  
  60.             if (GetIsError(hParser))
  61.             {
  62.                 //An error has occurred
  63.                 printf("\n\nAn error has occured... GlobalError==");
  64.                 dtochar(strResult, GetGlobalError(hParser));
  65.                 printf(strResult);
  66.  
  67.                 Result = 0;
  68.             }
  69.             else
  70.             {
  71.                dtochar(strResult, Result, 10, true);
  72.                printf("\n\nResult is ");
  73.                printf(strResult);
  74.             }
  75.          }
  76.         }
  77.  
  78.       //Delete of the sbParser object
  79.         DeleteParser(hParser);
  80.  
  81.       //Unloading of the csbparse.DLL
  82.         DeinitSTDsbParserDLL();
  83.       printf("\n\nClick RETURN");
  84.  
  85.         int c;
  86.       while ((c = getchar()) != '\n') {}
  87.       while ((c = getchar()) != '\n') {}
  88.    }
  89.    else {
  90.        printf("\n\nInitSTDsbParserDLL() failed");
  91.  
  92.         int c;
  93.       printf("\n\nClick RETURN");
  94.       while ((c = getchar()) != '\n') {}
  95.    }
  96.    return 0;
  97. }
  98.